package com.tvserials.notification.parser;

import com.tvserials.notification.dto.Episode;
import com.tvserials.notification.dto.Serial;
import com.tvserials.notification.exceptions.NetworkConnectionException;
import com.tvserials.notification.exceptions.PageParseException;
import com.tvserials.notification.vo.SourceType;
import com.tvserials.notification.vo.TvEpisodeFilterVO;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.List;

/**
 * Created by Alex on 19.04.2014.
 */
public class AlexFilmPageParser implements PageParser {
    @Override
    public List<Episode> parsePage(TvEpisodeFilterVO filterVO) throws NetworkConnectionException, PageParseException {
        try {
            Connection method = Jsoup
                    .connect("http://alexfilm.cc/login.php")
                    .data("login_username", "dokich")
                    .data("login_password", "Login1!")
                    .method(Connection.Method.POST).followRedirects(true);
            Connection.Response res = method.execute();
            Document parse = res.parse();

            Connection url = method.url("http://alexfilm.cc/tracker.php");
            Document document1 = url.get();

            Connection connection = Jsoup.connect("http://alexfilm.cc/tracker.php");
            connection.cookies(res.cookies());
            Document document = connection.get();

//            System.out.println(res.toString());
            System.out.println(parse.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Serial> parseSerialsList() throws NetworkConnectionException {
        return null;
    }

    @Override
    public SourceType getSourceType() {
        return null;
    }
}
